package com.lifang.test4;

import com.lifang.framework.annotation.beans.Component;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

@Slf4j
@Aspect
@Component
public class AopAspect {

    @Before("execution(* com.lifang.test4.UserService.*(..))")
    public void before() {
        log.info("AopAspect 我是拦截方法，我是before");
    }

    @After("execution(* com.lifang.test4.UserService.*(..))")
    public void after() {
        log.info("AopAspect 我是拦截方法，我是after");
    }

    @Around("execution(* com.lifang.test4.UserService.*(..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("AopAspect 我是拦截方法，我是around before");
        Object proceed = joinPoint.proceed();
        log.info("AopAspect 我是拦截方法，我是around after");
        return proceed;
    }

    @AfterReturning(value = "execution(* com.lifang.test4.UserService.*(..))", returning = "returnValue")
    public void afterRetuning(Object returnValue) {
        log.info("AopAspect 我是正常返回afterRetuningAdvice方法 " + returnValue);
    }

    @AfterThrowing(value = "execution(* com.lifang.test4.UserService.*(..))", throwing = "throwable")
    public void afterThrowing(Throwable throwable) {
        log.info("AopAspect 我是异常拦截afterThrowingAdvice方法 " + throwable);
    }

}
